package com.tarena.lbs.business.rpc;

import com.tarena.lbs.business.api.BusinessApi;
import com.tarena.lbs.business.api.pojo.BusinessDto;
import com.tarena.lbs.business.api.pojo.StoreDTO;
import com.tarena.lbs.business.dao.repository.StoreRepository;
import com.tarena.lbs.business.pojo.po.StorePO;
import com.tarena.lbs.business.pojo.query.AreaStoreQuery;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@DubboService
public class BusinessApiImpl implements BusinessApi {

    @Autowired
    private StoreRepository storeRepository;
    
    @Override
    public BusinessDto getBusinessById(Integer businessId) {
        return null;
    }

    @Override
    public List<StoreDTO> getStoreByAreaId(Integer areaId) {
        log.info("根据区域ID查询店铺: areaId={}", areaId);
        
        // 创建查询参数
        AreaStoreQuery areaStoreQuery = new AreaStoreQuery();
        List<Long> cityIdList = new ArrayList<>();
        cityIdList.add(Long.valueOf(areaId));
        areaStoreQuery.setCityIdList(cityIdList);
        
        // 查询店铺
        List<StorePO> storePOs = storeRepository.storeByCityList(areaStoreQuery);
        
        // 转换为DTO
        List<StoreDTO> storeDTOs = new ArrayList<>();
        if (storePOs != null && !storePOs.isEmpty()) {
            for (StorePO storePO : storePOs) {
                StoreDTO storeDTO = new StoreDTO();
                BeanUtils.copyProperties(storePO, storeDTO);
                storeDTOs.add(storeDTO);
            }
        }
        
        log.info("查询结果: 共{}条店铺数据", storeDTOs.size());
        return storeDTOs;
    }

}
